package com.next

class Attachment
{
    AttachmentType type
    String fileName
    String fileUrl
    String thumbnailUrl

    String description

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    Opportunity opportunity
    Contact contact
    Product product

    static constraints = {
        description nullable: true, blank: true, maxSize: 1024
        opportunity nullable: true, blank: true
        contact nullable: true, blank: true
        fileUrl maxSize: 512, nullable: true, blank: true
        thumbnailUrl maxSize: 512, nullable: true, blank: true
        product nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    def beforeInsert()
    {
        if (!fileUrl)
        {
            fileUrl = fileName
        }
    }
}
